/**
 * 
 */
package org.bankabeule.ui.actions;

import org.bankabeule.Tag;
import org.bankabeule.core.ModelManager;
import org.bankabeule.ui.Activator;
import org.bankabeule.ui.utils.Logger;
import org.bankabeule.ui.utils.UIUtils;
import org.bankabeule.ui.wizards.TagWizard;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * @author sdudoit
 *
 */
public class AddTagAction extends AbstractAction {


	/**
	 * TreeViewer
	 */
	private TreeViewer viewer;
	
	
	/**
	 * Constructor
	 * @param parent
	 */
	public AddTagAction(TreeViewer viewer) {
		super();
        this.viewer = viewer;
		setText("&Add tag ...");
		setId(getClass().getCanonicalName());
		setImageDescriptor(Activator.getImageDescriptor("Add.gif"));
		setEnabled(ModelManager.get().getModel() != null);
	}
	
	
	@Override
	public void run() {
		try {
			Object selection = ((StructuredSelection) viewer.getSelection()).getFirstElement();
			WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(),
					new TagWizard(null, (Tag) selection)) {

				@Override
				protected void configureShell(Shell newShell) {
					super.configureShell(newShell);
					UIUtils.center(newShell, getParentShell(), 400, 300);
				}
				
			};
			dialog.open();
		} catch (Exception e) {
			Logger.log(e);
		}
	}
	
}
